let baseURL = "";

// 客户端执行
if (import.meta.client) {
  const config = useRuntimeConfig();
  baseURL = config.public.apiBaseUrl;
}

/**
 * 聊天
 * @param body
 * @returns
 */
export const chat = (body: any): ReturnType<typeof $fetch> => {
  return $fetch(baseURL + "/gz_dome/chat", {
    method: "POST",
    body,
  });
};

/**
 * 上传文件
 * @param file
 * @returns
 */
export const uploadFile = (file: File): ReturnType<typeof $fetch> => {
  const formData = new FormData();
  formData.append("file", file);
  return $fetch(baseURL + "/api/upload", {
    method: "POST",
    body: formData,
  });
};

/**
 * 删除文件
 * @param filename
 * @returns
 */
export const deleteFile = (filename: string): ReturnType<typeof $fetch> => {
  return $fetch(baseURL + `/api/delete/${filename}`, {
    method: "DELETE",
    headers: {
      "Content-Type": "application/x-www-form-urlencoded",
    },
  });
};

/**
 * 根据子行业获取公司列表
 * @returns
 */
export const getRequir = (subindustry: string): ReturnType<typeof $fetch> => {
  return $fetch(baseURL + "/gz_dome/requir", {
    method: "GET",
    params: {
      subindustry,
    },
  });
};

/**
 * 获取企业列表
 * @returns
 */
export const getCompanyList = (): ReturnType<typeof $fetch> => {
  return $fetch(baseURL + "/gz_dome/list", {
    method: "GET",
  });
};

export const getFileList = (): ReturnType<typeof $fetch> => {
  return $fetch(baseURL + "/api/filelist", {
    method: "GET",
  });
};
